﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Library;
using System.Data;

/*
-- =============================================
-- Author:		Duong Hoang Vinh
-- Create date: 8/11/2011
-- Description:	RoleDetail Class
-- =============================================
*/

namespace BusinessLayer
{
   public class RoleDetail
    {
    #region "Variables and Properties"
    //Variables
        private int admin_ID;        
        private int role_ID;        
        private int role_Admin_Status;        

    //Properties
        public int Admin_ID
        {
            get { return admin_ID; }
            set { admin_ID = value; }
        }

        public int Role_ID
        {
            get { return role_ID; }
            set { role_ID = value; }
        }

        public int Role_Admin_Status
        {
            get { return role_Admin_Status; }
            set { role_Admin_Status = value; }
        }
    #endregion

    #region "Initial Methods"
        public RoleDetail() { }

        public RoleDetail(SqlDataReader sdr)
        {
            if (sdr != null && !sdr.IsClosed)
            {
                Admin_ID = sdr.GetInt32(0);
                if (sdr.IsDBNull(1))
                    Role_ID = sdr.GetInt32(1);
                if (sdr.IsDBNull(2))
                    Role_Admin_Status = sdr.GetInt32(2);
            }
        }
    #endregion

    #region "Business Methods"
    //Get All RoleDetail
        public static List<RoleDetail> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Role_Detail_SHOWALL";
            List<RoleDetail> lstRoleDetail = new List<RoleDetail>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);

            while (sdr.Read())
            {
                lstRoleDetail.Add(new RoleDetail(sdr));
            }

            return lstRoleDetail;
        }

    //Get One RoleDetail
        public static RoleDetail GetOne(int admin_ID, int role_ID)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Role_Detail_SHOWONE";
            RoleDetail roleDetail = new RoleDetail();
            SqlDataReader sdr;

            dbh.AddParameter("@Admin_ID", admin_ID);
            dbh.AddParameter("@Role_ID", role_ID);
            sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);

            if (sdr.Read())
            {
                roleDetail.Admin_ID = sdr.GetInt32(0);
                if (sdr.IsDBNull(1))
                    roleDetail.Role_ID = sdr.GetInt32(1);
                if (sdr.IsDBNull(2))
                    roleDetail.Role_Admin_Status = sdr.GetInt32(2);
            }

            return roleDetail;
        }

    //Insert RoleDetail
        public static void Insert(RoleDetail roleDetail)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Role_Detail_INSERT";

            dbh.AddParameter("@Admin_ID", roleDetail.Admin_ID);
            dbh.AddParameter("@Role_ID", roleDetail.Role_ID);

            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

    //Update RoleDetail
        public static void Update(RoleDetail roleDetail)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Role_Detail_UPDATE";

            dbh.AddParameter("@Admin_ID", roleDetail.Admin_ID);
            dbh.AddParameter("@Role_ID", roleDetail.Role_ID);

            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

    //Delete RoleDetail
        public static void Delete(int admin_ID, int role_ID)
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Role_Detail_DELETE";

            dbh.AddParameter("@Admin_ID", admin_ID);
            dbh.AddParameter("@Role_ID", role_ID);

            dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
        }
    #endregion
    }
}
